'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	
	let apiUrl = 'https://v2.alapi.cn/api/tophub'
	const {
		data
	} = await uniCloud.httpclient.request(apiUrl, {
		method: 'GET',
		data: {
			id:"K7GdaMgdQy",
			token: "K8NVh0xvERNNSX1l"
		},
		contentType: 'json',
		dataType: 'json'
	})
	
	if (data.code === 200) {
		const{
			data:data1
		}  = await uniCloud.httpclient.request(apiUrl, {
			method: 'GET',
			data: {
				id:"DpQvNABoNE",
				token: "K8NVh0xvERNNSX1l"
			},
			contentType: 'json',
			dataType: 'json'
		})
		if (data1.code === 200) {
			let date = new Date();
			let month = date.getMonth() + 1;
			let strDate = date.getDate();
			let res = await db.collection('douyin').add({
				dy_shi:data1.data,
				dy_sou: data.data,
				date:+new Date(),
				day:`${month}--${strDate}`
			})
			return res
		}
	}
};
